package com.example.demo.service.impl;

import com.example.demo.constant.SystemConstant;
import com.example.demo.dto.ClothingDTO;
import com.example.demo.dto.CommodityDTO;
import com.example.demo.mapper.StudentClothingMapper;
import com.example.demo.mapper.entity.Avatar;
import com.example.demo.mapper.entity.Clothing;
import com.example.demo.mapper.entity.StudentClothing;
import com.example.demo.service.StudentClothingService;
import com.example.demo.utils.PageBo;
import com.example.demo.utils.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Lucy
 * @create 2024-02-20 21:56
 */
@Service
public class StudentClothingServiceImpl implements StudentClothingService {

    @Autowired
    private StudentClothingMapper mapper;

    @Override
    public void insertStudentClothing(StudentClothing studentClothing) {
        mapper.insertStudentClothing(studentClothing);
    }

    @Override
    public PageVo<ClothingDTO> getClothingList(PageBo pageBo, int studentId, int type) {
        List<StudentClothing> studentClothingList =  mapper.selectStudentClothing(studentId);
        List<ClothingDTO> clothingDTOList = new ArrayList<>();
        for(StudentClothing studentClothing : studentClothingList){
            int clothingId = studentClothing.getClothingId();
            Clothing clothing = mapper.selectClothingById(clothingId);
            if(clothing.getType() != type){
                continue;
            }
            ClothingDTO clothingDTO = new ClothingDTO();
            clothingDTO.setClothingId(clothingId);
            clothingDTO.setClothingName(clothing.getClothingName());
            clothingDTO.setImageUrl(SystemConstant.aliyunOSSUrlPrefix + clothing.getImageUrl());
            clothingDTOList.add(clothingDTO);
        }
        return new PageVo<>(pageBo, clothingDTOList);
    }

    @Override
    public List<Avatar> selectAvatarListByStudentId(int studentId) {
        return mapper.selectAvatarListByStudentId(studentId);
    }

    @Override
    public void deleteAvatarListByStudentId(int studentId) {
        mapper.deleteAvatarListByStudentId(studentId);
    }

    @Override
    public Clothing selectClothingById(Integer clothingId) {
        return mapper.selectClothingById(clothingId);
    }

    @Override
    public void insertAvatar(Avatar avatar) {
        mapper.insertAvatar(avatar);
    }
}
